﻿#define _CRT_SECURE_NO_WARNINGS//模仿qsort的功能实现一个通用的冒泡排序
#include<stdio.h>
int cmp(const void* p3, const void* p4)
{
	if (*(int*)p3 > *(int*)p4)
		return 1;
	else if (*(int*)p3 < *(int*)p4)
		return -1;
	else
		return 0;
}
void swap(char* p1, char* p2, int sz)
{
	for (int i = 0; i < sz; i++)
	{
		char temp = *p1;
		*p1 = *p2;
		*p2 = temp;
		p1++;
		p2++;

	}
}
void print(int* arr, int n)
{
	for (int i = 0; i < n; i++)
	{
		printf("%d ", *(arr + i));
	}

}
void test1()
{
	int arr[] = { 1,2,3,5,6,4,8,9,7 };
	int sz = sizeof(arr[0]);
	int num = sizeof(arr) / sizeof(arr[0]);
	for (int i = 0; i < num - 1; i++)
	{
		for (int j = 0; j < num - 1 - i; j++)
		{
			if (cmp((char*)arr + j * sz, (char*)arr + (j + 1) * sz) > 0)
			{
				swap((char*)arr + j * sz, (char*)arr + (j + 1) * sz, sz);
			}

		}
	}
	print(arr, num);
}
int main()
{
	test1();

	return 0;
}